import 'package:flutter/material.dart';
import 'package:huajianshe_app/base/BaseState.dart';
import 'package:huajianshe_app/common/C.dart';
import 'package:huajianshe_app/common/TS.dart';
import 'package:huajianshe_app/common/load_image.dart';
import 'package:huajianshe_app/common/space.dart';
import 'package:huajianshe_app/pages/circle/model/CircleModel.dart';
import 'package:huajianshe_app/pages/main/MomentItem.dart';
import 'package:huajianshe_app/pages/main/model/MomentModel.dart';
import 'package:huajianshe_app/widget/AutoGridWidget.dart';


class UserMomentItem extends StatefulWidget {

  final bool hideTopLine; // 第一个元素需要隐藏上面一段线
  final MomentMonthData? data;
  final CircleInfo? circleInfo;

  const UserMomentItem(this.data, this.circleInfo, {Key? key,
    this.hideTopLine = false,
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _UserMomentItemState();
  }
}

class _UserMomentItemState extends BaseState<UserMomentItem> {
  @override
  Widget build(BuildContext context) {
    return Container(color: Colors.white, child: IntrinsicHeight(
        child: Row(crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max,
          children: [
            Container(width: 38,
              child: Center(child: Container(width: 14, color: Colors.transparent, height: double.infinity,
                  child: Stack(children: [
                    if (!widget.hideTopLine) Positioned(child: Container(height: 24, width: 1, color: Color(0xffe9e9e9)), top: 0, left: 6,),
                    Positioned(child: LoadImage('dot_in_line', width: 14, height: 14), top: 24),
                    Positioned(child: Container(height: double.infinity, width: 1, color: Color(0xffe9e9e9)), top: 38, left: 6, bottom: 0,),
                  ])
              ))
            ),
            Expanded(child: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                ...buildItems()
              ],
            )),
            W(13)
          ],
        )
    ));
  }

  List<Widget> buildItems() {
    List<Widget> result = [];
    if (widget.data?.posts?.isNotEmpty == true) {
      result.add(H(15));
      result.add(Text('${widget.data?.month}', style: TS(26, C.gray1A, fontWeight: FontWeight.bold)));
      result.add(Text('${widget.data?.viewNum}次浏览', style: TS(11, C.gray666)));
      result.add(H(10));
      widget.data?.posts?.forEach((element) {
        result.add(MomentItem(element, widget.circleInfo));
        result.add(H(10));
      });
      return result;
    }
    return [H(0)];
  }

}